<template>
  <el-dialog class="upload-img" :visible="dialogShow" center title="上传图片" @close="btnClose">
    <div class="center">
      <el-upload
        class="upload-demo"
        drag
        :data="d"
        name="img"
        action="admin/api/image/upload"
        :headers="headers"
        multiple
      >
        <i class="el-icon-upload" />
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
      </el-upload>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" size="small" @click="btnOk()">确定</el-button>
        <el-button size="small" @click="btnClose()">取消</el-button>
      </span>
    </div>
  </el-dialog>
</template>

<script>
import { getToken } from '@/utils/auth'
import { mapGetters, mapActions } from 'vuex'
export default {
  name: 'UploadImg',
  props: {
    dialogShow: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      d: { image_class_id: 1 },
      headers: {
        Authorization: `Bearer ${getToken()}`
      }
    }
  },
  computed: {
    ...mapGetters(['imageList'])
  },
  methods: {
    ...mapActions(['image/getImageList']),
    btnClose() {
      this.$emit('update:dialogShow', false)
    },
    btnOk() {
      this['image/getImageList']({ id: this.imageList.id, page: 1, limit: 8 })
      this.$message.success('上传成功')
      this.btnClose()
    }
  }
}
</script>
<style lang="scss" scoped>
.upload-img {
  ::v-deep .el-dialog {
    height: unset;

    .center {
      display: flex;
      align-items: center;

      .dialog-footer {
        margin-top: 40px;
      }
    }
  }

}
</style>
